package com.hq.bootdemo.service.impl;

import com.hq.bootdemo.entity.TypeEntity;
import com.hq.bootdemo.mapper.TypeMapper;
import com.hq.bootdemo.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

//@Service
//public class TypeServiceImpl implements TypeService {
//   @Resource
////           或者@Autowired(required = false)
//    TypeMapper typeMapper;
//    @Override
//    public List<TypeEntity> selectAll(String condition){
//        return typeMapper.selectAll(condition);
//    }
//
//    @Override
//    public boolean insertOne(TypeEntity typeEntity) {
//        if(typeEntity.getTName() == null || typeEntity.getTName() == "" )return false;
//        int row = typeMapper.insertOne(typeEntity);
//        if(row != 0){
//            return true;
//        }
//        return false;
//    }
//
//    @Override
//    public boolean delOne(Integer id) {
//        if(id == null || id == 0)return false;
//        int row = typeMapper.delOne(id);
//        return row != 0;
//    }
//
@Service

public class TypeServiceImpl implements TypeService {
    @Autowired(required = false)
    private TypeMapper typeMapper;

    @Override
    public List<TypeEntity> selectAll(String condition) {
        return typeMapper.selectAll(condition);
    }

    @Override
    public boolean insertOne(TypeEntity typeEntity) {
        if(typeEntity.getTName() == null || typeEntity.getTName() =="") return false;
        int row = typeMapper.insertOne(typeEntity);
        if(row != 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delOne(Integer id) {
        if(id == null || id == 0) return false;
        int row = typeMapper.delOne(id);
        return row !=0;
    }

    @Override
    public TypeEntity selectOne(Integer id) {
        return typeMapper.selectOne(id);
    }

    @Override
    public boolean update(TypeEntity type) {
        if(type == null || type.getTName() == null || type.getTName().equals(""))return false;
        int row = typeMapper.update(type);
        return row != 0;
    }

}
